// pages/manage/manage.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    token: "",
    num: [],
    data: [],
    result: [],
    checked: false,
  },
  tab(event) {
    var _this = this
    if (event.detail.index == 0) {
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/query/authorized/list`,

        header: {
          'content-type': 'application/json',
          TOKEN: _this.data.token
        },
        method: "post",
        success: function (data) {
        //console.log("请求的数据为: ", data.data.data);
          var boj = []
          data.data.data.forEach((i, l) => {
            boj.push("1")
          })
          _this.setData({
            data: data.data.data,
            num: boj
          })
        }
      })
    } else {
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/query/unauthorized/list`,

        header: {
          'content-type': 'application/json',
          TOKEN: _this.data.token
        },
        method: "post",
        success: function (data) {
        //console.log("请求的数据为: ", data.data.data);
          var boj = []
          data.data.data.forEach((i, l) => {
            boj.push("1")
          })
          _this.setData({
            data: data.data.data,
            num: boj
          })
        }
      })
    }
  },
  Deactivate(event) {
    var _this = this
    var boj = this.data.num
    boj.forEach((i, l) => {
      if (l == event.currentTarget.id) {
        boj[l] = 2
      }
    })
  //console.log(boj);
    this.setData({
      num: boj
    })
  //console.log(event.currentTarget.id);
    var obj = _this.data.data[event.currentTarget.id].id
  //console.log(obj);
    wx.request({
      url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply/enable/single`,
      data: {
        id: obj,
        status: 3
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        TOKEN: _this.data.token
      },
      method: "post",
      success: function (data) {
      //console.log("请求的数据为: ", data.data);

      }
    })
  },
  Deactivate1(event) {
    var _this = this
    var boj = this.data.num
    boj.forEach((i, l) => {
      if (l == event.currentTarget.id) {
        boj[l] = 1
      }
    })
  //console.log(boj);
    this.setData({
      num: boj
    })
  //console.log(event.currentTarget.id);
    var obj = _this.data.data[event.currentTarget.id].id
  //console.log(obj);
    wx.request({
      url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply/enable/single`,
      data: {
        id: obj,
        status: 4
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        TOKEN: _this.data.token
      },
      method: "post",
      success: function (data) {
      //console.log("请求的数据为: ", data.data);

      }
    })
  },
  onChange(event) {
    this.setData({
      result: event.detail,
    });
  //console.log(this.data.result);
  },
  onChange2(event) {
    this.setData({
      checked: event.detail,
    });
    if (this.data.checked == false) {
      this.setData({
        result: [],
      });
    } else {
      var object=[]
      this.data.data.forEach((i, l) => {
        object.push(`${l}`)
      })
      this.setData({
        result:object
      })
    //console.log(object);
    }
  },
  button() {
    var _this = this
    var obj
    if (this.data.result.length == 1) {
      obj = this.data.data[this.data.result].id
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply/approve/single`,
        data: {
          id: obj,
          status: 2
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          TOKEN: _this.data.token
        },
        method: "post",
        success: function (data) {
        //console.log("请求的数据为: ", data.data);
        }
      })
    } else {
      var obj1 = []
      this.data.result.forEach((i, l) => {
        obj = _this.data.data[i].id

        obj1.push(obj)
      })
    //console.log(obj1);
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply/approve/list`,
        data: {
          idList: obj1,
          status: 2
        },
        header: {
          'content-type': 'application/json',
          TOKEN: _this.data.token
        },
        method: "post",
        success: function (data) {
        //console.log("请求的数据为: ", data.data);

        }
      })
    }
  },
  button1() {
    var _this = this
    var obj
    if (this.data.result.length == 1) {
      obj = this.data.data[this.data.result].id
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply/approve/single`,
        data: {
          id: obj,
          status: 1
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          TOKEN: _this.data.token
        },
        method: "post",
        success: function (data) {
        //console.log("请求的数据为: ", data.data);
        }
      })
    } else {
      var obj1 = []
      this.data.result.forEach((i, l) => {
        obj = _this.data.data[i].id

        obj1.push(obj)
      })
    //console.log(obj1);
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply/approve/list`,
        data: {
          idList: obj1,
          status: 1
        },
        header: {
          'content-type': 'application/json',
          TOKEN: _this.data.token
        },
        method: "post",
        success: function (data) {
        //console.log("请求的数据为: ", data.data);

        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var v = wx.getStorageSync('token')
    var _this = this
    _this.setData({
      token: v,
    })
    wx.request({
      url: `https://fintech-wx.szjrgzjg.com//api/authorize/query/authorized/list`,

      header: {
        'content-type': 'application/json',
        TOKEN: _this.data.token
      },
      method: "post",
      success: function (data) {
      //console.log("请求的数据为: ", data.data.data);
        var boj = []
        data.data.data.forEach((i, l) => {
          boj.push("1")
        })
        _this.setData({
          data: data.data.data,
          num: boj
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})